package com.junxonline.common.dao.repository;

import com.junxonline.common.dao.model.Menu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @ClassName: UserRepository
 * @Description: 用户数据操作类
 * @author JunX
 */
@Repository
public interface MenuRepository extends JpaRepository<Menu, Long> {

    Menu findByMenuUrl(String menuUrl);

    @Query(value =
            "SELECT menu.* FROM sys_role_menu role_menu " +
            "LEFT JOIN sys_role role ON role.role_id = role_menu.role_id " +
            "LEFT JOIN sys_menu menu ON menu.menu_id = role_menu.menu_id " +
            "WHERE role.role_id = ?1 ORDER BY menu.menu_sort ASC;", nativeQuery = true)
    List<Menu> findMenusByRoleIdOrderByMenuSortAsc(Long roleId);

}
